import { defineStore } from 'pinia'

export const useLangStore = defineStore('lang', {
  state: () => {
    return {
      lang: [
        {
          lang: 'zh_cn',
          name: 'cn',
          value: '中文',
          active: true
        },
        {
          lang: 'en',
          name: 'en',
          value: 'EN',
          active: false
        }
      ]
    }
  },
  getters: {
    getLang: (state) => state.lang.filter((item) => item.active === true)[0].lang
  },
  actions: {
    changeLang(lang) {
      this.lang.forEach((item) => {
        item.lang === lang ? (item.active = true) : (item.active = false)
      })
    }
  }
})
